import MToast from './index.vue'

export default {
  install(Vue) {
    let instance = null
    const MToastConstructor = Vue.extend(MToast)
    Vue.prototype.$showToast = function (text) {
      if (instance) return
      instance = new MToastConstructor({
        data: {
          text,
          hidden: hideToast
        }
      }).$mount()
      document.body.appendChild(instance.$el)
      instance.show = true
    }

    function hideToast() {
      if (instance) {
        instance.show = false
        instance = null
      }
    }

    Vue.prototype.$hideToast = hideToast
  }
}
